home *** CD-ROM | disk | FTP | other *** search
- //----------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------
- //
- // Filename : winmain.cpp
- // Description : Main Win32 Functions
- // Author : Marnich van Rensburg (2002)
- //
- //----------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------
-
- // Note: Linker requires (winmm.lib opengl32.lib glu32.lib glaux.lib)
-
- #include "gamemain.h"
-
- //----------------------------------------------------------------------------------------
- // Globals
- //----------------------------------------------------------------------------------------
-
- bool StarFieldActive = true;
- bool SoundActive = true;
-
- //----------------------------------------------------------------------------------------
- // Variable/Function Declarations
- //----------------------------------------------------------------------------------------
-
- bool keys[256]; // Array Used For The Keyboard Routine
- bool active = true; // Window Active Flag Set To true By Default
- unsigned char KeyVal;
- unsigned long keyhold = 0; //Time keydown event
-
- GameMain CurrentGame;
-
- LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
-
- //----------------------------------------------------------------------------------------
- // Winmain Functions : WndProc
- //----------------------------------------------------------------------------------------
-
- LRESULT CALLBACK WndProc(HWND hWnd, // Handle For This Window
- UINT uMsg, // Message For This Window
- WPARAM wParam, // Additional Message Information
- LPARAM lParam) // Additional Message Information
- {
-
- switch (uMsg) // Check For Windows Messages
- {
- case WM_ACTIVATE: // Watch For Window Activate Message
- {
- if (!HIWORD(wParam)) // Check Minimization State
- {
- active = true; // Program Is Active
- }
- else
- {
- active = false; // Program Is No Longer Active
- }//if - else
-
- return 0; // Return To The Message Loop
- }//case
-
-
- case WM_SYSCOMMAND: // Intercept System Commands
- {
- switch (wParam) { // Check System Calls
- case SC_SCREENSAVE: // Screensaver Trying To Start?
- case SC_MONITORPOWER: // Monitor Trying To Enter Powersave?
- return 0; // Prevent From Happening
- }//switch
-
- break; // Exit
- }//case
-
-
- case WM_CLOSE: // Did We Receive A Close Message?
- {
- PostQuitMessage(0); // Send A Quit Message
- return 0; // Jump Back
- }//case
-
-
- case WM_KEYDOWN: // Is A Key Being Held Down?
- {
- KeyVal = wParam;
- if(keyhold == 0)
- {
- keys[wParam] = true; // If So, Mark It As true
- keyhold = 1;
- }else{
- keys[wParam] = false; // If So, Mark It As true
- keyhold++;
- }//if
- return 0; // Jump Back
- }
-
-
- case WM_KEYUP: // Has A Key Been Released?
- {
- keyhold = 0;
- keys[wParam] = false; // If So, Mark It As false
- return 0; // Jump Back
- }//case
-
-
- case WM_SIZE: // Resize The OpenGL Window
- {
- return 0; // Jump Back
- }//case
-
- }//switch
-
- return DefWindowProc(hWnd, uMsg, wParam, lParam); // Pass All Unhandled Messages To DefWindowProc
-
- }//WndProc
-
-
-
-
- //----------------------------------------------------------------------------------------
- // Winmain Functions : WinMain
- //----------------------------------------------------------------------------------------
-
- int WINAPI WinMain(HINSTANCE hInstance, // Instance
- HINSTANCE hPrevInstance, // Previous Instance
- LPSTR lpCmdLine, // Command Line Parameters
- int nCmdShow) // Window Show State
- {
- MSG msg;
- bool done = false; // Bool Variable To Exit Loop
-
- if (CurrentGame.Init()) // Initialize the game
- {
- CurrentGame.New(); // Starts a new game
-
- while(!done) // Loop While done = false
- {
- if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting?
- {
- if (msg.message == WM_QUIT) // Have We Received A Quit Message?
- {
- done = true; // If So done=true
- }
- else // If Not, Deal With Window Messages
- {
- TranslateMessage(&msg); // Translate The Message
- DispatchMessage(&msg); // Dispatch The Message
- }//if - else
- }
- else
- {
- if (keys[VK_ESCAPE]) // Check if there was a message
- {
- done = true;
- }
- else // if there wasn't a message
- {
-
- switch(CurrentGame.Mode)
- {
- case GAME_START_SCREEN:
- {
- CurrentGame.New(); // Starts a new game
- CurrentGame.StartScreen(KeyVal);
- break;
- }//case
-
- case GAME_ACTIVE:
- {
- CurrentGame.Play(KeyVal); // Enter Gameloop
- break;
- }//case
-
- case GAME_NEW_HIGHSCORE:
- {
- CurrentGame.GetHighScore(KeyVal); // Enter Gameloop
- break;
- }//case
-
- }//switch
-
- KeyVal = 0;
- }//if - else
- }//if - else
- }//while
-
- CurrentGame.Quit();
-
- }//if
-
- return(msg.wParam); // Return from the program
-
- }//WinMain